﻿using System;
using System.Collections.Generic;
using System.Text;
using SH;

namespace MTS
{
    class mtIPSServer : mtInterface, ImtIPSServer
    {
        public mtIPSServer()
             : base("mtIPSServer")
        {

        }

        protected override shErrorCode _Initialize()
        {
            BindEpic(emProgramType.emPT_CSS, ImtCSSServerCallback._classID);

            return shErrorCode.sh_ec_Success;
        }
        /// <summary>
        /// 主动获取某个站点的站点状态
        /// </summary>
        /// <returns></returns>
        shErrorCode ImtIPSServer.GetIpsStationStatus(string token, out mtIpsStationStatus status)
        {
            MTSSerializer sc = new MTSSerializer();

            var ec = __InvokeTwoWay(ImtIPSCallback._classID, ImtIPSCallback.IPSGetIpsStationStatus, token, ref sc);

            if (ec != 0)
            {
                status = null;

                return  ec;
            }

            status = new mtIpsStationStatus();

            sc.serialize(status);

            return  ec;
        }

        /// <summary>
        /// 判图服务下发判图任务，仅判图站支持
        /// </summary>
        /// <returns></returns>
         shErrorCode ImtIPSServer.SendIpsTask(string token, mtIpsTask task)
        {
            MTSSerializer sc = new MTSSerializer();

            sc.serialize(task);

            var ec = __InvokeTwoWay(ImtIPSCallback._classID, ImtIPSCallback.IPSIpsTask, token, ref sc);

            return  ec;
        }

        /// <summary>
        ///  获取相同类型的站点发送图像信息列表，根据imageList内的emIpsType自动选择。
        /// </summary>
        /// <returns></returns>
         shErrorCode ImtIPSServer.NotifyIpsImageList(mtIpsImageList imageList)
        {
            emProgramType pt = emProgramType.emPT_ALL;
            switch (imageList.IpsType)
            {
                case emIpsType.emSTTP_Judge:
                    pt = emProgramType.emPT_IPS3D; break;
                case emIpsType.emSTTP_Check:
                    pt = emProgramType.emPT_CBS; break;
                case emIpsType.emSTTP_Confirm:
                    pt = emProgramType.emPT_CFS; break;
                default:
                    return shErrorCode.sh_ec_NotFound;
            }

            MTSSerializer sc = new MTSSerializer();
            sc.serialize(imageList);

            return __InvokeOneWay(ImtIPSCallback._classID, ImtIPSCallback.IPSNotifyIpsImageList,pt, sc);
        }


        /// <summary>
        /// 判图服务下发高危报警状态
        /// </summary>
        /// <returns></returns>
         shErrorCode ImtIPSServer.NotifyHighRiskState(mtIpsHighRiskState req)
        {
            MTSSerializer sc = new MTSSerializer();
            sc.serialize(req);

            return __InvokeOneWay(ImtIPSCallback._classID, ImtIPSCallback.IPSNotifyHighRiskState, emProgramType.emPT_ALL,sc);
        }

        /// <summary>
        /// 判图服务通知确认站确认的结论
        /// </summary>
        /// <returns>
        /// </returns>
         shErrorCode ImtIPSServer.NotifyComfirmConclusion(mtIpsComfirmConclusion req)
        {
            MTSSerializer sc = new MTSSerializer();
            sc.serialize(req);

            return __InvokeOneWay(ImtIPSCallback._classID, ImtIPSCallback.IPSNotifyComfirmConclusion, emProgramType.emPT_CBS, sc);
        }

        // to RCS
        shErrorCode ImtIPSServer.DeleteImage(mtDeleteImageDemand req, out mtDeleteImageReply rsp)
        {
            MTSSerializer sc = new MTSSerializer();

            sc.serialize(req);

            var ec = __InvokeTwoWay(ImtCSSServerCallback._classID, ImtCSSServerCallback.CSSServerDeleteImage, ref sc);

            if (ec != 0)
            {
                rsp = null;

                return  ec;
            }

            rsp = new mtDeleteImageReply();

            sc.serialize(rsp);

            return  ec;
        }

        shErrorCode ImtIPSServer.SaveImage(mtSaveImageRequest req, out mtSaveImageResponse rsp)
        {
            MTSSerializer sc = new MTSSerializer();

            sc.serialize(req);

            var ec = __InvokeTwoWay(ImtCSSServerCallback._classID, ImtCSSServerCallback.CSSServerSaveImage, ref sc);

            if (ec != 0)
            {
                rsp = null;

                return  ec;
            }

            rsp = new mtSaveImageResponse();

            sc.serialize(rsp);

            return  ec;
        }
       
    }
}
